const {UserLoginDao} = require('../dao/login')
const {generateToken} = require('../../core/util')
const {Auth} = require('../../middlewares/auth')


class LoginManager {
  // 管理员登录
  static async userLogin(params) {
    const {account, pwd} = params
    // 验证账号密码是否正确
    const admin = await UserLoginDao.verify(account, pwd);
    let obj = { 
      token: generateToken(admin.id, Auth.ADMIN),
      nickname: admin.nickname,
      is_student: admin.is_student,
      mail: admin.mail,
      work_number: admin.work_number,
      id: admin.id,
      account: admin.account,
      status: admin.status,
      pwd: admin.pwd,
      number: admin.number,
      img: admin.img ? admin.img : '',
    }
    return obj
  }
}

module.exports = {
  LoginManager
}
